package com.mengya.utils;

import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.gzcwt.entity.Notice;
import com.gzcwt.entity.Resource;
import com.gzcwt.entity.Test;
import com.mengya.ui.Conf;

public class FileDBO {
	public SQLiteDatabase db;

	public void createDB(Context context) {
		DBOpenHelper dbHelper = new DBOpenHelper(context, Conf.DB_NAME);
		db = dbHelper.getWritableDatabase();
	}

	// 向表File 插入一条记录
	public void insertIntoFiles(Resource notice) {
		try {
			System.out.println("lance test" + notice);
			ContentValues value = new ContentValues();
			value.put("id", notice.getId());
			value.put("category", notice.getResourceName());
			value.put("name", notice.getName());
			value.put("url", notice.getUrl());
			value.put("type", notice.getResourceType());
			value.put("status", notice.getStatus());
			value.put("update_time", "2013-03-11 00:02:19");
			value.put("start_length", 100l);
			value.put("size", 100l);
			db.insert("file", null, value);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// insert into test information
	public void insertIntoTests(Test test) {
		try {
			// Integer 50 外键+主键 引用表1的ID
			// Integer 50 主键2 题库序号
			// String 500 非空 内容
			// String 100 非空 选项
			// String 50 非空 答案
			// Boolean 2 false 是否通过
			// String 1 非空 单T多C判断F
			System.out.println("lance test" + test);
			ContentValues value = new ContentValues();
			value.put("file_id", test.getFile_id());
			value.put("id", test.getId());
			value.put("content", test.getContent());
			value.put("choice", test.getChoice());
			value.put("da_an", test.getDaAn());
			value.put("type", test.getType());

			db.insert("test", null, value);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 根据id设置已读公告
	public void setNoticeReaded(int id) {
		// ContentValues value=new ContentValues();
		// value.put("is_read", 1);
		// String[] s = new String[1];
		// s[0]=id+"";
		// db.update("notice", value, "id=?", s);
	}

	// 获取未读公告
	public List<Notice> getNoticeUnread() {
		// List<Notice> noticeList = new ArrayList<Notice>();
		// Cursor cursor=db.query("notice", new
		// String[]{"id","title","content","public_time","public_depart"},
		// "is_read=?", new String[]{"0"},null ,null,null);
		//
		// while(cursor.moveToNext()){
		// Notice notice = new Notice();
		// notice.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex("id"))));
		// notice.setTitle(cursor.getString(cursor.getColumnIndex("title")));
		// notice.setContent(cursor.getString(cursor.getColumnIndex("content")));
		// notice.setPublicDepart(cursor.getString(cursor.getColumnIndex("public_depart")));
		// notice.setPublicTime(cursor.getString(cursor.getColumnIndex("public_time")));
		// noticeList.add(notice);
		// }
		// return noticeList;
		return null;
	}

	// 获取已读公告
	public List<Notice> getNoticeHis() {
		// List<Notice> noticeList = new ArrayList<Notice>();
		// Cursor cursor=db.query("notice", new
		// String[]{"id","title","content","public_time","public_depart"},
		// "is_read=1", null,null ,null,null);
		//
		// while(cursor.moveToNext()){
		// Notice notice = new Notice();
		// notice.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex("id"))));
		// notice.setTitle(cursor.getString(cursor.getColumnIndex("title")));
		// notice.setContent(cursor.getString(cursor.getColumnIndex("content")));
		// notice.setPublicDepart(cursor.getString(cursor.getColumnIndex("public_depart")));
		// notice.setPublicTime(cursor.getString(cursor.getColumnIndex("public_time")));
		// noticeList.add(notice);
		// }
		// return noticeList;
		return null;
	}

	// 关闭数据库
	public void closeDB() {
		db.close();
	}
}